package com.lcy.springtest.conf;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * @author lichenyang
 * @create 2021-04-16 9:44 上午
 */
public class MyFilter implements TypeFilter {
    /**
     * @param metadataReader: 读取到当前正在扫描的类信息
     * @param metadataReaderFactory: 可以获取到其他任何的类信息
     * @return
     * @throws IOException
     */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        System.out.println("进入 MyFilter");
        // 获取当前注解的信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        // 获取当前类资源 ( 类的路径 )
        Resource resource = metadataReader.getResource();

        // 获取域当前正在扫描的类的类信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        String className = classMetadata.getClassName();
        // 如果获取的类名中包含er, 则返回true
        if(className.contains("er")){
            System.out.println("className: "+className + ", 返回 true");
            return true;
        }
        System.out.println("className: "+className + ", 返回 true");
        return false;
    }
}
